<?php
if($_SESSION['group_id']!=1){redir("./");exit;}

if($_POST['op']=='register'){
	$dep_id=$_POST['dep_id'];
	$branch_name=$_POST['branch_name'];
	
	if(!$branch_name)$err="กรุณากรอก ชื่อสาขา";
	else{
		$sql="insert into branch(branch_name,dep_id) values('$branch_name','$dep_id')";
		mysql_query($sql);
		redir("?mod=a.listbranch",5);
		die("<div id=com_msg>เพิ่มสาขาเรียบร้อยแล้วกรุณารอสักครู่ <img src=images/load.gif></div>");
	}
}
?>
<div class="box">
	<h2>เพิ่มสาขา</h2>
	<?php if($err)echo "<div id=error_msg>$err</div>";?>
	<div class="boxContent">
		<p>
	  <form method="post" enctype="multipart/form-data">
<table width="99%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td><strong>ภาควิชา</strong></td>
    <td>
	<select name="dep_id">
		<?php
		$sql="select * from department order by dep_id";
		$res=mysql_query($sql);
		while($dep=mysql_fetch_assoc($res)){
			$select=($_POST['dep_id']==$dep['dep_id'])?'selected':'';
			echo "<option value='$dep[dep_id]' $select>$dep[dep_name]</option>";
		}
		?>
	</select>
	</td>
  </tr>
	    		<tr>
		  			<td width="120"><strong>ชื่อสาขา</strong></td>
					<td><input name="branch_name" type="text" id="branch_name" value="<?php echo $branch_name;?>" /></td>
	    		</tr>
	  		</table>
			<table width="99%" border="0" cellspacing="2" cellpadding="2">
	    		<tr>
		  			<td align="center"><input type="submit" class="button" name="Submit" value="เพิ่มสาขา" />
	  			    <input name="op" type="hidden" id="op" value="register" /></td>
	    		</tr>
	  		</table>
	  </form>
		</p>
	</div>
</div>